
void main(void)
{   
#ifdef TEXTURE_ARRAY_ID
  vec3 texCoord;
  texCoord.xy = vTexCoord.xy*cb_GroundShadow.u_Scale.xy + cb_GroundShadow.u_Translate.xy;
  texCoord.z  = TEXTURE_ARRAY_ID;
  float z =  vTexture(s_SourceTex, texCoord).x;
#else //MonoShadow
  vec2  texCoord  = vTexCoord.xy*cb_GroundShadow.u_Scale.xy + cb_GroundShadow.u_Translate.xy;
  float z         = vTexture(s_SourceTex, texCoord.xy).x;

#ifdef GROUND_CLIPPING
  vec4  ptView    = vec4(texCoord * 2.0 - 1.0, z * 2.0 - 1.0, 1.0);
  ptView = cb_GroundShadow_Auto.u_LightViewProjMatrixToObjectView * ptView;
  
  if (vDot(ptView.xyz - cb_GroundShadow_Auto.u_GroundViewPosition, cb_GroundShadow_Auto.u_GroundViewNormal) < 0)
  {
    z = 1.0;
  }
#endif

#endif
  
  vec4 col = vec4(z<0.999 ? 1.0 : 0.0);

#ifdef SPOT_BLUR
  vec2 coord = vFma(texCoord.xy, vec2(2.0), vec2(-1.0));
  float ratio = vMax(0, 1.0 - vDot(coord, coord));
  col *= ratio;
#endif

  FRAGCOLOR = col;
}

